//package com.yuan.spring.logAspect;
//
//import ch.qos.logback.classic.spi.ILoggingEvent;
//import ch.qos.logback.core.UnsynchronizedAppenderBase;
//import com.mongodb.BasicDBObject;
//import org.springframework.beans.BeansException;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.stereotype.Component;
//
///**
// * mongoAppender
// * logback
// * 继承 applicationContextAware  可以让静态的applicationContext  = applicationContext
// * 从而使spring的环境保存到静态变量中 取的时候可以通过静态方法获取到spring 的实例
// * Created by 袁恩光 on 2017/11/30.
// */
//@Component
//public class MongoDBAppender extends UnsynchronizedAppenderBase<ILoggingEvent> implements ApplicationContextAware {
//
//    private static ApplicationContext applicationContext;
//
//    @Override
//    public void setApplicationContext(ApplicationContext ac) throws BeansException {
//        applicationContext = ac;
//    }
//
//    @Override
//    protected void append(ILoggingEvent eventObject) {
//        MongoTemplate mongoTemplate = applicationContext.getBean("mongoRiskTemplate", MongoTemplate.class);
//        if (mongoTemplate != null) {
//            BasicDBObject mongo = new BasicDBObject();
//            mongo.append("level", eventObject.getLevel().toString());
//            mongo.append("logger", eventObject.getLoggerName());
//            mongo.append("thread", eventObject.getThreadName());
//            mongo.append("message", eventObject.getFormattedMessage());
//            mongoTemplate.insert(mongo, "process_log");
//        }
//    }
//
//}